<?php
namespace app\admin\controller;

use app\common\AdminController;
use app\admin\model\Worker as WM;
use app\admin\model\WorkerDepartment as WDM;
use app\admin\validate\WorkerValidate as WV;

class Worker extends AdminController
{
    protected $validate = WV::class;

    protected $model = WM::class;

    public function index()
    {
        return view();
    }

    /**
     * [datalist 数据表格数据]
     * @return [type] [description]
     */
    public function datalist()
    {
        $data = $this->datalists(false);
        foreach ($data['rows'] as &$rows) {
            $rows->hidden(['passwd']);
            $rows->depart_name = isset($rows->depart->name) ? $rows->depart->name : '';
        }
        return $this->successRender($data);
    }

    /**
     * [新增/修改 职员]
     * @return [type] [description]
     */
    public function save()
    {
        $id         = $this->request->param('id', 0, 'intval');
        $detail     = WM::find($id);
        $departs    = WDM::column('name', 'id');
        return view('', compact('detail', 'departs'));
    }
}
